package com.atguigu.spzx.cloud.order.controller;

import com.atguigu.spzx.cloud.api.UserFeignClient;
import com.atguigu.spzx.cloud.entity.Order;
import com.atguigu.spzx.cloud.entity.User;
import com.atguigu.spzx.cloud.order.service.OrderService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping(value = "/api/order")
@RefreshScope
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private OrderService orderService ;

    @Autowired
    private UserFeignClient userFeignClient;

    @Value("${testconfigvalue}")
    private String testValue;

    @GetMapping(value = "/findOrderByOrderId/{orderId}")
    public Order findOrderByOrderId(@PathVariable("orderId") Long orderId, HttpServletRequest request) {
/*        String headerMessage = request.getHeader("Truth");
        System.out.println(headerMessage);*/
        System.out.println("nacos配置中心拿到的值:"+testValue);
        Order order = orderService.findOrderByOrderId(orderId);
        Long userId = order.getUserId();
        //User user = restTemplate.getForObject("http://spzx-cloud-user/api/user/findUserByUserId/" + userId, User.class);
        User user = userFeignClient.queryById(userId);
        System.out.println(user);
        order.setUser(user);
        return order;
    }

}